﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Core.Entity;
using System.Data;

namespace Core.Dao
{
    class CountryDao
    {
        public bool insert(Country country)
        {
            object[,] param = {
                {"@Name", country.Name},
                {"@Desc", country.Desc},
            };
            String sql = "insert into COUNTRIES(CNT_NAME, CNT_DESC) " +
                "values(@Name, @Desc)";
            return DB.exec(sql, param);
        }

        public bool update(Country country)
        {
            object[,] param = {
                {"@Name", country.Name},
                {"@Desc", country.Desc},
                {"@id", country.Id},
            };
            String sql = "update COUNTRIES set CNT_NAME = @Name, CNT_DESC = @Desc " +
                "where CNT_ID = @id";
            return DB.exec(sql, param);
        }

        public bool delete(int id)
        {
            object[,] param = {
                {"@id", id}   
            };
            String sql = "delete from COUNTRIES where CNT_ID = @id";
            return DB.exec(sql, param);
        }

        public bool delete(String ids)
        {
            object[,] param = {
                {"@ids", ids}   
            };
            String sql = "delete from COUNTRIES where CNT_ID in (" + ids + ")";
            return DB.exec(sql);
        }

        public DataTable get(int id)
        {
            object[,] param = {
                {"@id", id}   
            };
            String sql = "select * from COUNTRIES where CNT_ID = @id";
            return DB.getData(sql, param);
        }

        public DataTable getAll()
        {
            String sql = "select * from COUNTRIES order by CNT_NAME";
            return DB.getData(sql);
        }
    }
}
